home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / H / tmp / datum.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-06  |  7.2 KB  |  344 lines

  1. /*
  2.  * datum.h --
  3.  *    POSTGRES abstract data type datum representation definitions.
  4.  *
  5.  * Note:
  6.  *
  7.  * Port Notes:
  8.  *  Postgres makes the following assumption about machines:
  9.  *
  10.  *  sizeof(Datum) == sizeof(char *) == sizeof(long) == 4
  11.  *
  12.  *  Postgres also assumes that
  13.  *
  14.  *  sizeof(char) == 1
  15.  *
  16.  *  and that 
  17.  *
  18.  *  sizeof(short) == 2
  19.  *
  20.  *  If your machine meets these requirements, Datums should also be checked
  21.  *  to see if the positioning is correct.
  22.  *
  23.  *    This file is MACHINE AND COMPILER dependent!!!
  24.  */
  25.  
  26. #ifndef    DatumIncluded        /* Include this file only once */
  27. #define DatumIncluded    1
  28.  
  29. /*
  30.  * Identification:
  31.  */
  32. #define DATUM_H    "$Header: /private/postgres/src/lib/H/tmp/RCS/datum.h,v 1.14 1991/01/09 19:01:43 sp Exp $"
  33.  
  34. typedef struct AnyStruct {
  35.     char    character;
  36.     double  largeFloat;
  37. } AnyStruct;
  38.  
  39. typedef unsigned long Datum;
  40.  
  41. /*
  42.  * We want to pad to the right on Sun computers and to the right on
  43.  * the others.
  44.  * 
  45.  */
  46.  
  47. /*
  48.  * kai: Don't use the right-padding functions on the 386. They break postgres
  49.  * badly!
  50.  */
  51. #ifdef NOTDEF
  52.  
  53. #define GET_1_BYTE(datum)   ((((long) (datum)) & 0xff000000) >> 24)
  54. #define GET_2_BYTES(datum)  ((((long) (datum)) & 0xffff0000) >> 16)
  55. #define GET_4_BYTES(datum)  (datum)
  56. #define SET_1_BYTE(value)   (((long) (value)) << 24)
  57. #define SET_2_BYTES(value)  (((long) (value)) << 16)
  58. #define SET_4_BYTES(value)  (value)
  59.  
  60. #endif
  61.  
  62. #if defined(sequent) || defined(mips) || defined(sun) || defined(sparc) || defined(i386)
  63.  
  64. #define GET_1_BYTE(datum)   (((Datum) (datum)) & 0x000000ff)
  65. #define GET_2_BYTES(datum)  (((Datum) (datum)) & 0x0000ffff)
  66. #define GET_4_BYTES(datum)  ((Datum) (datum))
  67. #define SET_1_BYTE(value)   (((Datum) (value)) & 0x000000ff)
  68. #define SET_2_BYTES(value)  (((Datum) (value)) & 0x0000ffff)
  69. #define SET_4_BYTES(value)  ((Datum) (value))
  70.  
  71. #endif
  72.  
  73. /*
  74.  * DatumGetChar --
  75.  *    Returns character value of a datum.
  76.  */
  77.  
  78. #define DatumGetChar(X) ((char) GET_1_BYTE(X))
  79.  
  80. /*
  81.  * CharGetDatum --
  82.  *    Returns datum representation for a character.
  83.  */
  84.  
  85. #define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
  86.  
  87. /*
  88.  * DatumGetInt8 --
  89.  *    Returns 8-bit integer value of a datum.
  90.  */
  91.  
  92. #define DatumGetInt8(X) ((int8) GET_1_BYTE(X))
  93.  
  94. /*
  95.  * Int8GetDatum --
  96.  *    Returns datum representation for an 8-bit integer.
  97.  */
  98.  
  99. #define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
  100.  
  101. /*
  102.  * DatumGetUInt8 --
  103.  *    Returns 8-bit unsigned integer value of a datum.
  104.  */
  105.  
  106. #define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
  107.  
  108. /*
  109.  * UInt8GetDatum --
  110.  *    Returns datum representation for an 8-bit unsigned integer.
  111.  */
  112.  
  113. #define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
  114.  
  115. /*
  116.  * DatumGetInt16 --
  117.  *    Returns 16-bit integer value of a datum.
  118.  */
  119.  
  120. #define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
  121.  
  122. /*
  123.  * Int16GetDatum --
  124.  *    Returns datum representation for a 16-bit integer.
  125.  */
  126.  
  127. #define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
  128.  
  129. /*
  130.  * DatumGetUInt16 --
  131.  *    Returns 16-bit unsigned integer value of a datum.
  132.  */
  133.  
  134. #define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
  135.  
  136. /*
  137.  * UInt16GetDatum --
  138.  *    Returns datum representation for a 16-bit unsigned integer.
  139.  */
  140.  
  141. #define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
  142.  
  143. /*
  144.  * DatumGetInt32 --
  145.  *    Returns 32-bit integer value of a datum.
  146.  */
  147.  
  148. #define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
  149.  
  150. /*
  151.  * Int32GetDatum --
  152.  *    Returns datum representation for a 32-bit integer.
  153.  */
  154.  
  155. #define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
  156.  
  157. /*
  158.  * DatumGetUInt32 --
  159.  *    Returns 32-bit unsigned integer value of a datum.
  160.  */
  161.  
  162. #define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
  163.  
  164. /*
  165.  * UInt32GetDatum --
  166.  *    Returns datum representation for a 32-bit unsigned integer.
  167.  */
  168.  
  169. #define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
  170.  
  171. /*
  172.  * DatumGetFloat32 --
  173.  *    Returns 32-bit floating point value of a datum.
  174.  */
  175.  
  176. #define DatumGetFloat32(X) ((float32) GET_4_BYTES(X))
  177.  
  178. /*
  179.  * Float32GetDatum --
  180.  *    Returns datum representation for a 32-bit floating point number.
  181.  */
  182.  
  183. #define Float32GetDatum(X) ((Datum) SET_4_BYTES(X))
  184.  
  185. /*
  186.  * DatumGetFloat64 --
  187.  *    Returns 64-bit floating point value of a datum.
  188.  */
  189.  
  190. #define DatumGetFloat64(X) ((float64) GET_4_BYTES(X))
  191.  
  192. /*
  193.  * Float64GetDatum --
  194.  *    Returns datum representation for a 64-bit floating point number.
  195.  */
  196.  
  197. #define Float64GetDatum(X) ((Datum) SET_4_BYTES(X))
  198.  
  199. /*
  200.  * DatumGetPointer --
  201.  *    Returns pointer value of a datum.
  202.  */
  203.  
  204. #define DatumGetPointer(X) ((Pointer) GET_4_BYTES(X))
  205.  
  206. /*
  207.  * PointerGetDatum --
  208.  *    Returns datum representation for a pointer.
  209.  */
  210.  
  211. #define PointerGetDatum(X) ((Datum) SET_4_BYTES(X))
  212.  
  213. /*
  214.  * DatumGetPointerPointer --
  215.  *    Returns pointer to pointer value of a datum.
  216.  */
  217.  
  218. #define DatumGetPointerPointer(X) ((Pointer *) GET_4_BYTES(X))
  219.  
  220. /*
  221.  * PointerPointerGetDatum --
  222.  *    Returns datum representation for a pointer to pointer.
  223.  */
  224.  
  225. #define PointerPointerGetDatum(X) ((Datum) SET_4_BYTES(X))
  226.  
  227. /*
  228.  * DatumGetStructPointer --
  229.  *    Returns pointer to structure value of a datum.
  230.  */
  231.  
  232. #define DatumGetStructPointer(X) ((AnyStruct *) GET_4_BYTES(X))
  233.  
  234. /*
  235.  * StructPointerGetDatum --
  236.  *    Returns datum representation for a pointer to structure.
  237.  */
  238.  
  239. #define StructPointerGetDatum(X) ((Datum) SET_4_BYTES(X))
  240.  
  241. /*
  242.  * DatumGetName --
  243.  *    Returns name value of a datum.
  244.  */
  245.  
  246. #define DatumGetName(X) ((Name) GET_4_BYTES(X))
  247.  
  248. /*
  249.  * NameGetDatum --
  250.  *    Returns datum representation for a name.
  251.  */
  252.  
  253. #define NameGetDatum(X) ((Datum) SET_4_BYTES(X))
  254.  
  255. /*
  256.  * DatumGetObjectId --
  257.  *    Returns object identifier value of a datum.
  258.  */
  259.  
  260. #define DatumGetObjectId(X) ((ObjectId) GET_4_BYTES(X))
  261.  
  262. /*
  263.  * ObjectIdGetDatum --
  264.  *    Returns datum representation for an object identifier.
  265.  */
  266.  
  267. #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
  268.  
  269. /*--------------------------------------------------------
  270.  * SOME NOT VERY PORTABLE ROUTINES ???
  271.  *--------------------------------------------------------
  272.  *
  273.  * In the implementation of the next routines we assume the following:
  274.  *
  275.  * A) if a type is "byVal" then all the information is stored in the
  276.  * Datum itself (i.e. no pointers involved!). In this case the
  277.  * length of the type is always greater than zero and less than
  278.  * "sizeof(Datum)"
  279.  * B) if a type is not "byVal" and it has a fixed length, then
  280.  * the "Datum" always contain a pointer to a stream of bytes.
  281.  * The number of significant bytes are always equal to the length of thr
  282.  * type.
  283.  * C) if a type is not "byVal" and is of variable length (i.e. it has
  284.  * length == -1) then "Datum" always points to a "struct varlena".
  285.  * This varlena structure has information about the actual length of this
  286.  * particular instance of the type and about its value.
  287.  */
  288.  
  289. /*---------------
  290.  * datumGetSize
  291.  * find the "real" length of a datum
  292.  */
  293. extern
  294. Size
  295. datumGetSize ARGS((
  296.     Datum    value,
  297.     ObjectId    type,
  298.     bool    byVal,
  299.     Size    len
  300. ));
  301.  
  302. /*---------------
  303.  * datumCopy
  304.  * make a copy of a datum.
  305.  */
  306. extern
  307. Datum
  308. datumCopy ARGS((
  309.     Datum    value,
  310.     ObjectId    type,
  311.     bool    byVal,
  312.     Size    len
  313. ));
  314.  
  315. /*---------------
  316.  * datumFree
  317.  * free space that *might* have been palloced by "datumCopy"
  318.  */
  319. extern
  320. void
  321. datumFree  ARGS((
  322.     Datum    value,
  323.     ObjectId    type,
  324.     bool    byVal,
  325.     Size    len
  326. ));
  327.  
  328. /*---------------
  329.  * datumIsEqual
  330.  * return true if thwo datums are equal, false otherwise.
  331.  * XXX : See comments in the code for restrictions!
  332.  */
  333. extern
  334. bool
  335. datumIsEqual ARGS((
  336.     Datum    value1,
  337.     Datum    value2,
  338.     ObjectId    type,
  339.     bool    byVal,
  340.     Size    len
  341. ));
  342.  
  343. #endif    /* !defined(DatumIncluded) */
  344.